<template>
  <div class="content-front">
    <!-- 公告栏优化 -->
    <div class="front-notice">
      <i class="el-icon-bell pulse"></i>
      <div class="notice-slider">
        <transition name="slide-fade">
          <span class="notice-text" :key="top">{{ top }}</span>
        </transition>
      </div>
    </div>
    
    <!-- 头部优化 -->
    <div class="front-header" :class="{ 'header-scroll': isScrolled }">
      <div class="front-header-left">
        <img src="../assets/imgs/logo.png" alt="logo" class="logo-image">
        <div class="title">GR计协</div>
      </div>
      

      <div class="front-header-center">
        <div class="front-header-nav">
          <el-menu :default-active="$route.path" mode="horizontal" router>
            <el-menu-item index="/front/home">
              <i class="el-icon-house"></i>首页
            </el-menu-item>
            <el-menu-item index="/front/repairs">
              <i class="el-icon-service"></i>维修中心
            </el-menu-item>
            <el-menu-item index="/front/association">
              <i class="el-icon-info"></i>关于我们
            </el-menu-item>        
          </el-menu>
        </div>
      </div>

      <div class="front-header-actions">
        <div class="weixin-container" @mouseenter="showQRCode" @mouseleave="hideQRCode">
          <a class="weixin" href="javascript:">
            <i class="fab fa-weixin"></i>
            <span>微信公众号</span>
          </a>
          <transition name="qr-fade">
            <div class="qr-popup" v-show="isQRCodeVisible">
              <div class="qr-inner">
                <img src="../assets/imgs/gzh.jpg" alt="微信二维码" class="qr-image">
                <div class="qr-info">
                  <div class="qr-title">全希工作室</div>
                  <div class="qr-desc">扫码关注我们</div>
                </div>
              </div>
              <div class="qr-arrow"></div>
            </div>
          </transition>
        </div>
        <a @click="$router.push('/front/repair-list')" class="repair-btn">
          <i class="el-icon-document"></i>
          <span>维修单</span>
        </a>
      </div>

      <div class="front-header-right">
        <div v-if="!user.username" class="auth-buttons">
          <el-button type="primary" @click="$router.push('/login')" class="login-btn">登录</el-button>
          <el-button @click="$router.push('/register')" class="register-btn">注册</el-button>
        </div>
        <div v-else class="user-container">
          <el-dropdown trigger="click">
            <div class="user-profile">
              <div class="avatar-wrapper">
                <img :src="user.avatar" alt="avatar" class="avatar">
                <div class="avatar-overlay">
                  <i class="el-icon-arrow-down"></i>
                </div>
              </div>
              <span class="username">{{ user.username }}</span>
            </div>
            <el-dropdown-menu slot="dropdown" class="user-dropdown">
              <el-dropdown-item @click.native="person">
                <i class="el-icon-user"></i> 个人中心
              </el-dropdown-item>
              <el-dropdown-item @click.native="logout">
                <i class="el-icon-switch-button"></i> 退出登录
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
      </div>
    </div>

    <!-- 主体内容 -->
    <div class="main-body">
      <router-view ref="child" @update:user="updateUser" />
    </div>

    <!-- 底部优化 -->
    <div class="front-footer">
      <div class="footer-content">
        <div class="footer-main">
          <div class="footer-left">
            <a href="https://ca.seig.edu.cn/" target="_blank" class="school-link">
              <img src="../assets/imgs/hyplogo.png" alt="logo" class="footer-logo">
              <span>GR计协&&慧云跑团队共同开发</span>
            </a>
          </div>

          <div class="footer-center">
            <div class="quick-links">
              <router-link to="/front/home">首页</router-link>
              <router-link to="/front/repairs">维修中心</router-link>
              <router-link to="/front/association">关于我们</router-link>
              <router-link to="/front/repair-list">维修单</router-link>
            </div>
          </div>

          <div class="footer-right">
            <div class="contact-info">
              <span><i class="el-icon-location"></i> 广州市从化区经济开发区广从南路548号</span>
              <span><i class="el-icon-message"></i> @ca.seig.edu.cn</span>
            </div>
          </div>
        </div>

        <div class="footer-bottom">
          <span >© 2025 ca.seig.edu.cn All Rights Reserved</span>
          <span>广州软件学院计算机协会</span>
        </div>
      </div>

      <!-- 返回顶部按钮 -->
      <div class="back-to-top" 
           v-show="showBackToTop" 
           @click="scrollToTop"
           :class="{ 'back-to-top-show': showBackToTop }">
        <i class="el-icon-top"></i>
      </div>
    </div>
  </div>
</template>

<script>

export default {
  name: "FrontLayout",

  data () {
    return {
      top: '',
      notice: [],
      user: JSON.parse(localStorage.getItem("xm-user") || '{}'),
      isQRCodeVisible: false,
      isScrolled: false,
      showBackToTop: false,
    }
  },

  mounted() {
    this.loadNotice()
    window.addEventListener('scroll', this.handleScroll)
  },
  beforeDestroy() {
    window.removeEventListener('scroll', this.handleScroll)
  },
  methods: {
    handleScroll() {
      this.isScrolled = window.scrollY > 50
      this.showBackToTop = window.scrollY > 300
    },
    showQRCode() {
      this.isQRCodeVisible = true
    },
    hideQRCode() {
      this.isQRCodeVisible = false
    },
    loadNotice() {
      this.$request.get('/notice/selectAll').then(res => {
        this.notice = res.data
        if (this.notice && this.notice.length) {
          this.startNoticeRotation()
        }
      })
    },
    startNoticeRotation() {
      let i = 0
      this.top = this.notice[0].content
      setInterval(() => {
        i = (i + 1) % this.notice.length
        this.top = this.notice[i].content
      }, 2500)
    },
    updateUser() {
      this.user = JSON.parse(localStorage.getItem('xm-user') || '{}')   // 重新获取下用户的最新信息
    },
    // 退出登录
    logout() {
      localStorage.removeItem("xm-user");
      this.$router.push("/login");
    },
    person() {
      this.$router.push("/front/person");
    },
    scrollToTop() {
      window.scrollTo({
        top: 0,
        behavior: 'smooth'
      })
    }
  }

}
</script>

<style scoped>
.content-front {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background-color: #f5f7fa;
}

/* 公告栏样式 */
.front-notice {
  padding: 12px 24px;
  background: linear-gradient(135deg, #e6f3ff 0%, #ffffff 100%);
  display: flex;
  align-items: center;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.front-notice i {
  color: #409EFF;
  margin-right: 10px;
  font-size: 18px;
}

.notice-slider {
  overflow: hidden;
  height: 20px;
}

.slide-fade-enter-active, .slide-fade-leave-active {
  transition: all 0.5s ease;
}

.slide-fade-enter {
  transform: translateY(20px);
  opacity: 0;
}

.slide-fade-leave-to {
  transform: translateY(-20px);
  opacity: 0;
}

/* 头部样式优化 */
.front-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: 64px;
  padding: 0 24px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  transition: all 0.3s ease;
}

.header-scroll {
  height: 56px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.1);
}

.front-header-left {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  margin-right: 20px;
}

.logo-image {
  height: 40px;
  margin-right: 12px;
  transition: transform 0.3s ease;
}

.logo-image:hover {
  transform: scale(1.05);
}

.title {
  font-size: 22px;
  font-weight: 600;
  color: #303133;
  background: linear-gradient(120deg, #409EFF, #36cfc9);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* 中间导航区域 */
.front-header-center {
  flex: 1;
  display: flex;
  justify-content: center;
}

.front-header-nav {
  margin: 0;
  flex: 1;
  max-width: 600px;
}

.el-menu {
  display: flex;
  justify-content: center;
  width: 100%;
}

.el-menu-item {
  font-size: 15px;
  font-weight: 500;
  color: #606266 !important;
}

.el-menu-item.is-active {
  color: #409EFF !important;
  font-weight: 600;
}

/* 操作按钮样式 */
.front-header-actions {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 0 24px;
  flex-shrink: 0;
}

.weixin-container {
  position: relative;
  z-index: 1000;
}

.weixin {
  display: flex;
  align-items: center;
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 14px;
  color: #606266;
  transition: all 0.3s ease;
}

.weixin:hover {
  background-color: #f0f9eb;
  color: #409EFF;
}

.weixin i {
  margin-right: 6px;
  font-size: 16px;
}

.repair-btn {
  background-color: #ecf5ff;
  color: #409EFF;
}

.repair-btn:hover {
  background-color: #dbedff;
}

.repair-btn i {
  margin-right: 6px;
  font-size: 16px;
}

/* 用户信息区域 */
.front-header-right {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  min-width: 120px;
}

.auth-buttons {
  display: flex;
  gap: 12px;
}

.user-container {
  position: relative;
  margin-left: 20px;
}

.user-profile {
  display: flex;
  align-items: center;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 40px;
  background: rgba(255, 255, 255, 0.1);
  transition: all 0.3s ease;
}

.user-profile:hover {
  background: rgba(64, 158, 255, 0.1);
}

.avatar-wrapper {
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  overflow: hidden;
  margin-right: 8px;
  border: 2px solid #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
}

.avatar {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.avatar-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: all 0.3s ease;
}

.avatar-overlay i {
  color: white;
  font-size: 16px;
  transform: translateY(10px);
  transition: all 0.3s ease;
}

.user-profile:hover .avatar-overlay {
  opacity: 1;
}

.user-profile:hover .avatar-overlay i {
  transform: translateY(0);
}

.user-profile:hover .avatar {
  transform: scale(1.05);
}

.username {
  font-size: 14px;
  font-weight: 500;
  color: #303133;
  margin: 0 4px;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 下拉菜单样式 */
.user-dropdown {
  margin-top: 5px;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  overflow: hidden;
}

.el-dropdown-menu__item {
  display: flex;
  align-items: center;
  padding: 10px 20px;
  transition: all 0.3s ease;
}

.el-dropdown-menu__item i {
  margin-right: 8px;
  font-size: 16px;
}

.el-dropdown-menu__item:hover {
  background-color: #ecf5ff;
  color: #409EFF;
}

/* 动画效果 */
@keyframes dropdownFadeIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.el-dropdown-menu--popup {
  animation: dropdownFadeIn 0.3s ease;
}

/* 响应式调整 */
@media screen and (max-width: 1200px) {
  .front-header {
    padding: 0 16px;
  }
  
  .front-header-actions {
    margin: 0 16px;
  }
}

@media screen and (max-width: 768px) {
  .front-header-actions {
    display: none;
  }
  
  .front-header-nav {
    margin: 0 10px;
  }
  
  .title {
    font-size: 18px;
  }
  
  .front-header-left {
    margin-right: 10px;
  }
}

/* 二维码弹窗样式 */
.qr-popup {
  position: absolute;
  top: calc(100% + 15px);
  left: 50%;
  transform: translateX(-50%);
  background: white;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  padding: 12px;
  width: 120px;
  z-index: 1000;
}

.qr-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.qr-image {
  width: 100px;
  height: 100px;
  border-radius: 4px;
  transition: transform 0.3s ease;
}

.qr-info {
  margin-top: 8px;
  text-align: center;
}

.qr-title {
  font-size: 12px;
  font-weight: 500;
  color: #303133;
  margin-bottom: 2px;
}

.qr-desc {
  font-size: 11px;
  color: #909399;
}

.qr-arrow {
  position: absolute;
  top: -6px;
  left: 50%;
  transform: translateX(-50%) rotate(45deg);
  width: 12px;
  height: 12px;
  background: white;
  box-shadow: -2px -2px 5px rgba(0, 0, 0, 0.06);
}

/* 动画效果 */
.qr-fade-enter-active,
.qr-fade-leave-active {
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  transform-origin: top center;
}

.qr-fade-enter,
.qr-fade-leave-to {
  opacity: 0;
  transform: translateX(-50%) scale(0.95);
}

/* 悬浮效果 */
.qr-popup:hover .qr-image {
  transform: scale(1.02);
}

/* 响应式调整 */
@media screen and (max-width: 768px) {
  .qr-popup {
    width: 100px;
  }
  
  .qr-image {
    width: 80px;
    height: 80px;
  }
  
  .qr-title {
    font-size: 11px;
  }
  
  .qr-desc {
    font-size: 10px;
  }
}

/* 暗色模式适配 */
@media (prefers-color-scheme: dark) {
  .user-profile {
    background: rgba(255, 255, 255, 0.05);
  }
  
  .user-profile:hover {
    background: rgba(64, 158, 255, 0.15);
  }
  
  .username {
    color: #e0e0e0;
  }
}

/* 底部样式优化 */
.front-footer {
  background: #2c3e50;
  padding: 20px 0;
  color: #fff;
  margin-top: auto;
  position: relative;
  z-index: 10;
}

.footer-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

.footer-main {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.footer-left {
  flex: 1;
}

.school-link {
  display: flex;
  align-items: center;
  text-decoration: none;
  color: #fff;
  transition: opacity 0.3s;
}

.school-link:hover {
  opacity: 0.8;
}

.footer-logo {
  height: 30px;
  margin-right: 10px;
}

.footer-center {
  flex: 2;
  text-align: center;
}

.quick-links {
  display: flex;
  justify-content: center;
  gap: 20px;
}

.quick-links a {
  color: #fff;
  text-decoration: none;
  font-size: 14px;
  transition: color 0.3s;
  position: relative;
}

.quick-links a:hover {
  color: #409EFF;
}

.quick-links a::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 100%;
  height: 1px;
  background: #409EFF;
  transform: scaleX(0);
  transition: transform 0.3s;
}

.quick-links a:hover::after {
  transform: scaleX(1);
}

.footer-right {
  flex: 1;
  text-align: right;
}

.contact-info {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.7);
}

.contact-info span {
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.contact-info i {
  margin-right: 5px;
  color: #409EFF;
}

.footer-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 0;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.5);
}

/* 返回顶部按钮样式 */
.back-to-top {
  position: fixed;
  right: 30px;
  bottom: 30px;
  width: 40px;
  height: 40px;
  background: #409EFF;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  cursor: pointer;
  transition: all 0.3s;
  opacity: 0;
  transform: translateY(20px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.back-to-top-show {
  opacity: 1;
  transform: translateY(0);
}

.back-to-top:hover {
  background: #66b1ff;
  transform: translateY(-3px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

/* 响应式设计 */
@media screen and (max-width: 768px) {
  .footer-main {
    flex-direction: column;
    gap: 20px;
    text-align: center;
  }

  .footer-right {
    text-align: center;
  }

  .contact-info span {
    justify-content: center;
  }

  .quick-links {
    flex-wrap: wrap;
  }

  .footer-bottom {
    flex-direction: column;
    gap: 5px;
    text-align: center;
  }
}
</style>